package com.denlaku.longan.lock;

import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 *
 * @author tianx
 */
@Component
@ConditionalOnProperty(prefix = "longan", value = "deployMode", havingValue = "MULTI")
public class RedissonLockFactory implements LockFactory {
    @Autowired
    private RedissonClient redissonClient;

    @Value("${spring.application.name}")
    private String applicationName;

    @Override
    public Lock getLock(final String name) {
        return new RedissonLock(redissonClient.getLock(applicationName + ":lock:" + name));
    }
}
